from datetime import datetime
from app import db

# 积分记录模型
class PointRecord(db.Model):
    __tablename__ = 'tb_point_record'
    
    record_id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='记录ID(主键)')
    user_id = db.Column(db.BigInteger, db.ForeignKey('tb_user.user_id', ondelete='CASCADE'), nullable=False, comment='用户ID')
    mq_points = db.Column(db.Integer, nullable=False, comment='积分变动(正值增加,负值减少)')
    type = db.Column(db.Integer, default=1, comment='类型(1-购买盲盒,2-评价,3-签到,4-兑换,5-活动)')
    description = db.Column(db.String(255), comment='变动描述')
    reference_id = db.Column(db.BigInteger, comment='关联ID(订单ID或其他)')
    create_time = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
    
    # 关联 - 使用back_populates与User类匹配
    user = db.relationship('User', back_populates='point_records')
    
    def __repr__(self):
        return f'<PointRecord {self.record_id}>' 